<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>信息列表</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script type="text/javascript">
		$(function(){
			
			// 公告状态下拉列表
			$('#articleKind').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"-1","text":"全部"},
					{"value":"1","text":"未开始"},
					{"value":"2","text":"进行中"},
					{"value":"3","text":"已结束"}
				]
			});
			$('#noticeStatus').combobox("setValue",2);
			
			// 公告类型下拉列表
			$('#noticeKind').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"-1","text":"全部"},
					{"value":"1","text":"财务"},
					{"value":"2","text":"中心仓"},
					{"value":"3","text":"市场/销售"},
					{"value":"4","text":"采购/商品"},
					{"value":"5","text":"系统调整"},
					{"value":"6","text":"其他"},
				]
			});
			$('#noticeKind').combobox("setValue",-1);
			loadTable();
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
				rownumbers:true,
				singleSelect:true,
				pagination:true,
				pageSize:10,
				pageList:[10,20,30,50,100],
		 		url:'${pageContext.request.contextPath }/admin/notice/listNotice',
		 		queryParams:{
		 			 status:$('#noticeStatus').combobox("getValue"),
		 			 kind:$('#noticeKind').combobox("getValue"),
		 			 username:$('#username').val()
		 		},
	    		columns:[[
					{field:'notice_id',title:'编号',align:'center',width:45},
					{field:'username',title:'发布人',align:'center',width:80},
					{field:'notice_title',title:'文章标题',align:'left',width:150},
					{field:'notice_kind',title:'文章类型',align:'left',width:80},
					{field:'start_date',title:'公告开始日期',width:90,align:'center',formatter: function (value, row, index) {
						var status=value.substr(0,10);
						return status;
					}},
					{field:'end_date',title:'公告结束日期',width:90,align:'center',formatter: function (value, row, index) {
						var status=value.substr(0,10);
						return status;
					}},
					{field:'notice_content',title:'公告内容',width:300,align:'center'},
					{field:'create_time',title:'创建时间',width:130,align:'center'},   
					{field:'operation',title:'操作选项',width:200,align:'center',formatter: function (value, row, index) {
						var str = '<a href="javascript:edit('+row.notice_id+')" name="edit" class="easyui-linkbutton" ></a>';
						str=str+' | <a href="javascript:del('+row.notice_id+')" name="clear"  class="easyui-linkbutton" ></a>';				
						str=str+' | <a href="javascript:manage('+row.notice_id+')" name="manage"  class="easyui-linkbutton" ></a>';
						return str;
					}}
	 			]],
				onLoadSuccess:function(data){  
			        $("a[name='clear']").linkbutton({text:'删除',plain:true,iconCls:'icon-my-minus'});
			        $("a[name='edit']").linkbutton({text:'编辑',plain:true,iconCls:'icon-edit'});
			        $("a[name='manage']").linkbutton({text:'管理',plain:true,iconCls:'icon-my-manage'}); 
				}
			});
		}
		
		function findData(){
			loadTable();
		}
		
		// 删除公告
		function del(noticeId){
			$.messager.confirm('Confirm', '您确认要删除该公告信息吗?（一旦删除，不可恢复）', function(r){
				if (r){
					$.post("${pageContext.request.contextPath}/admin/notice/delNotice",{noticeId:noticeId},
					function(data){
						if(data=="1"){
							$.messager.alert('系统消息','公告信息删除成功！');
							$('#dg').datagrid('reload');  
						}else{
							$.messager.alert('系统消息','公告信息删除失败！');
						}
							
					},"text");
					
				}else{
					$.messager.alert('系统消息','删除操作取消！');
				}
			});
		}
		
		// 查看公告标题图片
		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src="${pageContext.request.contextPath }"+imgUrl;
			image.setAttribute("src",src );
		}
		
		function edit(noticeid){
			show("${pageContext.request.contextPath}/admin/notice/editBefore/"+noticeid,"修改公告信息");
			
		}
		
		function doAddNotice(){
			show("${pageContext.request.contextPath}/admin/notice/addBefore","新增公告信息");
		}
		
		// 重置密码功能，重置的密码为随机生成的6位数字
		function resetPass(userid){
			var pass=getRandomPass();
			$.post("${pageContext.request.contextPath}/admin/user/resetPass",{userid:userid,password:pass},
				function(data){
					if(data=="0"){
						$.messager.alert('系统消息','<span style=\"color:red;\">密码重置失败，请稍后再试！</span>');	 
					}else{
						$.messager.alert('系统消息','密码重置成功！<br/>重置后的密码为：'+pass);
						$('#dg').datagrid('reload'); 
					}
						
				},"text");
		}
		

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}

	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
    <table id="dg" title="文章信息列表" style="width:1200px;height:445px" toolbar="#searchtool"></table>
    <div id="searchtool" style="padding:5px">  
       <span style="margin:0px 12px;">文章类型:</span><input id="articleKind" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">公告类型:</span><input id="noticeKind" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">创建人:</span><input id="username" class="easyui-textbox" style="width:180px;height:26px"/> 
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a> 
       <a href="javascript:doAddNotice()" class="easyui-linkbutton" data-options="iconCls:'icon-my-add'" style="width:100px;margin:0px 3px;">新增公告</a> 
    </div>
  </body>
</html>
<html>